Skip to content

refactor(sortingrenderer): Replace custom doubly linked list with std::list in SortingNodeStruct#2810

Merged
xezon merged 5 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/sorting-renderer-std-list
Jun 20, 2026
Merged

refactor(sortingrenderer): Replace custom doubly linked list with std::list in SortingNodeStruct#2810
xezon merged 5 commits into
TheSuperHackers:mainfrom
stephanmeesters:refactor/sorting-renderer-std-list

Conversation

@stephanmeesters

Copy link
Copy Markdown

For the sorting renderer, this changes DLListClass and its nodes DLNodeClass with the std::list equivalent.

Tested on a custom map to verify that transparent particle rendering stays the same.

In the sorting renderer a doubly linked list is used for insertion sort in Insert_Triangles. In a follow-up I have some code ready to optimize the insertion of particles.

@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors the sorting renderer by replacing the custom DLListClass<SortingNodeStruct> / DLNodeClass intrusive linked list with std::list<SortingNodeStruct*>, and consolidates the duplicated insertion-sort logic into a new private helper Insert_To_Sorted_List.

  • Sort semantics preserved: the new Insert_To_Sorted_List iterates sorted_list front-to-back and inserts before the first node with lower Z, matching the original descending-Z ordering (farthest-first for painter's algorithm). The old special-case guard for a single-element DLListClass was a quirk of that API and is no longer needed.
  • Memory recycling intact: Get_Sorting_Struct pops from clean_list, nodes are returned to clean_list after flushing, and Deinit deletes all remaining nodes from both lists — all correctly ported to std::list semantics.
  • Assertion scope change: the vertex_buffer/vertex_count WWASSERT checks in Insert_Triangles were moved from unconditional code into #ifdef WWDEBUG, while the equivalent checks in Insert_VolumeParticle remain unconditional; this inconsistency is worth aligning.

Confidence Score: 5/5

Safe to merge; the refactoring is a clean like-for-like replacement with no logic changes to sort order or memory ownership.

The insertion-sort logic, memory recycling via clean_list, and back-to-front rendering order are all faithfully preserved. The only deviation from a pure mechanical port is moving two WWASSERT checks into a debug-only block in Insert_Triangles while leaving equivalent checks unconditional in Insert_VolumeParticle, which is a minor inconsistency rather than a correctness defect.

sortingrenderer.cpp around the Insert_Triangles vertex-buffer assertions (lines 256–260) to decide whether to align them with Insert_VolumeParticle.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Replaces DLListClass/DLNodeClass with std::list for sorted_list and clean_list; extracts insertion sort logic into Insert_To_Sorted_List; sort semantics and memory recycling are preserved, but vertex buffer assertions are inconsistently moved to debug-only in Insert_Triangles while remaining unconditional in Insert_VolumeParticle.
Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.h Adds private static declaration for Insert_To_Sorted_List; no other changes, existing #pragma once and forward declarations are unaffected.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Insert_Triangles / Insert_VolumeParticle"] --> B["Get_Sorting_Struct()"]
    B --> C{clean_list empty?}
    C -- No --> D["pop_front() reuse node"]
    C -- Yes --> E["W3DNEW SortingNodeStruct"]
    D --> F["Fill node fields & transform center"]
    E --> F
    F --> G["Insert_To_Sorted_List(state)"]
    G --> H{iterate sorted_list}
    H -- "state.Z > node.Z" --> I["list::insert before node"]
    H -- "end of list" --> J["push_back"]
    I --> K["sorted_list (descending Z)"]
    J --> K
    K --> L["Flush()"]
    L --> M{buffer type?}
    M -- "SORTING" --> N["Insert_To_Sorting_Pool - Flush_Sorting_Pool - per-triangle sort"]
    M -- "other" --> O["Draw_Triangles directly"]
    N --> P["Release_Refs - clean_list.push_front"]
    O --> P
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["Insert_Triangles / Insert_VolumeParticle"] --> B["Get_Sorting_Struct()"]
    B --> C{clean_list empty?}
    C -- No --> D["pop_front() reuse node"]
    C -- Yes --> E["W3DNEW SortingNodeStruct"]
    D --> F["Fill node fields & transform center"]
    E --> F
    F --> G["Insert_To_Sorted_List(state)"]
    G --> H{iterate sorted_list}
    H -- "state.Z > node.Z" --> I["list::insert before node"]
    H -- "end of list" --> J["push_back"]
    I --> K["sorted_list (descending Z)"]
    J --> K
    K --> L["Flush()"]
    L --> M{buffer type?}
    M -- "SORTING" --> N["Insert_To_Sorting_Pool - Flush_Sorting_Pool - per-triangle sort"]
    M -- "other" --> O["Draw_Triangles directly"]
    N --> P["Release_Refs - clean_list.push_front"]
    O --> P
Loading

Reviews (5): Last reviewed commit: "Add insertion to sorted list into new fu..." | Re-trigger Greptile

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Jun 19, 2026

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything wrong but perhaps someone else can look over it too.

Comment thread Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Outdated
Comment thread Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Outdated
Comment thread Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
Comment thread Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp Outdated
@xezon xezon changed the title refactor(sortingrenderer): Replace custom doubly linked list with std::list refactor(sortingrenderer): Replace custom doubly linked list with std::list in SortingNodeStruct Jun 20, 2026
@xezon xezon merged commit 984db42 into TheSuperHackers:main Jun 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants